package com.itmyx.base.util.file;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import com.itmyx.base.util.log.Logger;

public class PropertiesUtils {
	private static final String config_file_properties = "/variable/config.properties";
	private static final Logger logger = Logger
			.getLogger(Logger.class);

	/**
	 * 根据文件路径，key获取value值
	 * @param filePath
	 * @param key
	 * @return
	 */
	public static String getValue(String filePath, String key) {
		Properties props = new Properties();
		InputStream in = null;
		String value = "";
		try {
			in = PropertiesUtils.class.getResourceAsStream(filePath);
			props.load(in);
			value = props.getProperty(key);
		} catch (Exception e) {
			logger.error(e);
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				logger.error(e);
			}
		}
		return value;
	}


	/**
	 * 根据key获取value
	 * @param key
	 * @return
	 */
	public static String getValue(String key) {
		Properties props = new Properties();
		InputStream in = null;
		String value = "";
		try {
			in = PropertiesUtils.class
					.getResourceAsStream(config_file_properties);
			props.load(in);
			value = props.getProperty(key);
		} catch (Exception e) {
			logger.error(e);
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				logger.error(e);
			}
		}
		return value;
	}
}